<template>
  <div>
    <el-button type="primary" @click="show = true">{{ title }}</el-button>
    <rz-dialog
      :dialogVisible.sync="show"
      :title="title"
      width="50%"
      @oncancel="oncancel"
      @onconfirm="onconfirm"
    >
      <el-form :model="query" label-width="120px" ref="ruleForm" :rules="rules">
        <el-row>
          <el-col :span="12">
            <el-form-item label="添加日期">
              <el-date-picker
                :picker-options="pickerOptions"
                v-model="query.dateStr"
                type="date"
                size="small"
                width="100%"
                value-format="yyyy-MM-dd"
                :clearable="false"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          
        </el-row>
   <el-row>
        <el-col :span="24">
            <el-form-item label="扣分类型">
<el-row>
        <el-col :span="12">
          <!-- category -->
          <template v-if="category==1">
           <el-radio-group v-model="radio" @change="(e)=>query.score=e">
    <el-radio label="-50">重大事故</el-radio>
    <el-radio label="-30">一般事故</el-radio>
  </el-radio-group>
          </template>
             <template v-else-if="category==3">
           <el-radio-group v-model="radio" @change="(e)=>query.score=e">
    <el-radio label="-10">查实</el-radio>
  </el-radio-group>
          </template>
              <template v-else-if="category==4">
           <el-radio-group v-model="radio" @change="(e)=>query.score=e">
   <el-radio label="-5">警告</el-radio>
    <el-radio label="-10">立案</el-radio>
  </el-radio-group>
          </template>
  <!-- <el-radio-group v-model="radio" @change="(e)=>query.score=e">
    <el-radio label="-5">警告</el-radio>
    <el-radio label="-10">立案</el-radio>
  </el-radio-group> -->
        </el-col>
        <el-col :span="12">

              <el-input-number v-model="query.score" disabled></el-input-number>
        </el-col>
</el-row>
            </el-form-item>
          </el-col>
   </el-row>
        <el-form-item label="扣分原因及理由" prop="reasonReason">
          <el-input
            type="textarea"
            :rows="4"
            placeholder="请输入扣分原因及理由"
            v-model="query.reasonReason"
          >
          </el-input>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="操作人">
              <el-input v-model="query.operator" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="部门名称">
              <el-input v-model="query.source" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </rz-dialog>
  </div>
</template>
<script>
import { saveUnitFoodManualRecord } from "@/api/modules/interpretation";

export default {
  props: {
    title: {
      type: String,
      default: "",
    },
    category: {
      type: String,
      default: "1",
    },
  },
  // props:[],
  // 页面加载
  created() {
    this.query.dateStr = this.$moment().format("YYYY-MM-DD");
    if(this.category==1){
        this.query.score="-30"
        this.radio="-30"
    }else if(this.category==3){
  this.query.score="-10"
        this.radio="-10"

    }else{
       this.query.score="-5"
           this.radio="-5"
    }
  },
  // 页面加载完成
  mounted() {},
  //实例销毁之前
  beforeDestroy() {},
  //实例销毁后
  destroyed() {},
  data() {
    return {
      show: false,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      query: {
        fsuperviseunitId: sessionStorage.getItem("interpretation"),
        operator: sessionStorage.getItem("logname"),
        reasonReason: "",
        score: "-5",
        indexDay: "",
        indexMonth: "",
        indexYear: "",
        source: sessionStorage.getItem("unitName"),
        dateStr: "",
      },
      rules: {
        reasonReason: [
          { required: true, message: "请输入扣分原因及理由", trigger: "blur" },
        ],
      },
      radio:"-5"
    };
  },
  // 方法
  methods: {
    oncancel() {
      this.query.reasonReason = "";
      this.$refs.ruleForm.resetFields();
    },
    onconfirm() {
      this.query.indexDay = this.$moment(this.query.dateStr).format("DD");
      this.query.indexMonth = this.$moment(this.query.dateStr).format("MM");
      this.query.indexYear = this.$moment(this.query.dateStr).format("YYYY");
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          saveUnitFoodManualRecord({
            category: this.category,
            ...this.query,
          }).then((res) => {
            this.query.reasonReason = "";
            this.$emit("success");
            this.show = false;
            this.$success("保存成功");
          });
        }
      });
    },
  },
  // 监听属性
  watch: {},
  // 组件
  components: {},
  // 计算属性
  computed: {},
};
</script>

<style lang="scss" scoped>
</style>